using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnimyCtl : MonoBehaviour
{
    public int roadIndex = 0;
    
    public EnimyData data;
    // Start is called before the first frame update
    void Start()
    {
        data = GetComponent<EnimyData>();
    }

    // Update is called once per frame
    void Update()
    {
        
        Vector3 target = GameManager.Instance.getMoveTarget(roadIndex,out bool canMove);
        if (!canMove)
        {
            //血量减少
            //当前地图怪物减少
            //到达终点,销毁自己
            Destroy(gameObject);
        }

        Vector3 direction = (target-transform.position).normalized;
        
        transform.Translate(direction*Time.deltaTime*data.speed,Space.World);
        if (Vector3.Distance(transform.position, target) <= 0.01)
        {
            roadIndex++;
        } 
        
    }

    private void OnCollisionEnter2D(Collision2D other)
    {
        Debug.Log("被子弹击中！");
        if (other.gameObject.tag.Equals("Bullet"))//被子弹击中
        {
            Destroy(other.gameObject);
            //敌人减血
            // Destroy(gameObject);
            Debug.Log("被子弹击中！");
        }
    }
}
  